<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- saved from url=(0054)http://us2.php.net/manual/en/function.odbc-connect.php -->
<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><STYLE>#gview-cmenu {
  position: absolute;
  border: 1px solid #ccc;
  background: #fff;
  margin: 0;
  padding: 0;
  top: 0;
  left: 0;
  z-index: 10000;
  list-style-type: none;
  -webkit-box-shadow: 0 3px 5px rgba(0, 0, 0, .5);
}

#gview-cmenu:focus {
  outline: none;
}

.gview-cmenu-item {
  margin: 0;
  padding: 5px 7px;
  cursor: default;
  font-size: 13px;
  font-family: arial, san-serif;
  color: #000;
  -webkit-user-select: none;
}

.gview-cmenu-item:hover {
  background-color: #F0F7F9;
}

.gview-cmenu-item:first-child {
  border-bottom: 1px solid #ddd;
}

.gview-hidden {
  display: none;
}
</STYLE><HEAD profile="http://purl.org/NET/erdf/profile"><META http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <TITLE>PHP: odbc_connect - Manual</TITLE>
 <STYLE type="text/css" media="all">
  @import url("/styles/site.css");
  @import url("/styles/mirror.css");
 </STYLE>
 <!--[if IE]><![if gte IE 6]><![endif]-->
  <STYLE type="text/css" media="print">
   @import url("/styles/print.css");
  </STYLE>
 <!--[if IE]><![endif]><![endif]-->
 
 <LINK rel="shortcut icon" href="http://us2.php.net/favicon.ico">
 <LINK rel="contents" href="http://us2.php.net/manual/en/index.php">
 <LINK rel="index" href="http://us2.php.net/manual/en/ref.uodbc.php">
 <LINK rel="prev" href="http://us2.php.net/manual/en/function.odbc-commit.php">
 <LINK rel="next" href="http://us2.php.net/manual/en/function.odbc-cursor.php">
 <LINK rel="schema.dc" href="http://purl.org/dc/elements/1.1/">
 <LINK rel="schema.rdfs" href="http://www.w3.org/2000/01/rdf-schema#">
 <LINK rev="canonical" rel="self alternate shorter shorturl shortlink" href="http://php.net/odbc-connect">
 <LINK rel="license" href="http://creativecommons.org/licenses/by/3.0/" about="#content">
 <LINK rel="canonical" href="http://php.net/manual/en/function.odbc-connect.php">
 <SCRIPT type="text/javascript" src="./PHP_odbc_connect - Manual_files/userprefs.js"></SCRIPT>
 <!--<BASE href="http://us2.php.net/manual/en/function.odbc-connect.php">--><BASE href=".">
 <META http-equiv="Content-language" value="en">
			<SCRIPT type="text/javascript" src="./PHP_odbc_connect - Manual_files/jquery.min.js"></SCRIPT>
			<SCRIPT type="text/javascript" src="./PHP_odbc_connect - Manual_files/jquery-ui.min.js"></SCRIPT>
<SCRIPT type="text/javascript">
$(document).ready(function() {
	var toggleImage = function(elem) {
		if ($(elem).hasClass("shown")) {
			$(elem).removeClass("shown").addClass("hidden");
			$("img", elem).attr("src", "/images/notes-add.gif");
		}
		else {
			$(elem).removeClass("hidden").addClass("shown");
			$("img", elem).attr("src", "/images/notes-reject.gif");
		}
	};

	$(".refsect1 h3.title").each(function() {
        url = "http://bugs.php.net/report.php?bug_type=Documentation+problem&amp;manpage=" + $(this).parent().parent().attr("id") + "%23" + $(this).text();
		$(this).parent().prepend("<div class='reportbug'><a href='" + url + "'>Report a bug</a></div>");
		$(this).prepend("<a class='toggler shown' href='#'><img src='/images/notes-reject.gif' /></a> ");
	});
	$("#usernotes .head").each(function() {
		$(this).prepend("<a class='toggler shown' href='#'><img src='/images/notes-reject.gif' /></a> ");
	});
	$(".refsect1 h3.title .toggler").click(function() {
		$(this).parent().siblings().slideToggle("slow");
		toggleImage(this);
		return false;
	});
	$("#usernotes .head .toggler").click(function() {
		$(this).parent().next().slideToggle("slow");
		toggleImage(this);
		return false;
	});
});
</SCRIPT>

</HEAD><BODY>

<DIV id="headnav">
 <A href="http://us2.php.net/" rel="home"><IMG src="./PHP_odbc_connect - Manual_files/php.gif" alt="PHP" width="120" height="67" id="phplogo"></A>
 <DIV id="headmenu">
  <A href="http://us2.php.net/downloads.php">downloads</A> |
  <A href="http://us2.php.net/docs.php">documentation</A> |
  <A href="http://us2.php.net/FAQ.php">faq</A> |
  <A href="http://us2.php.net/support.php">getting help</A> |
  <A href="http://us2.php.net/mailing-lists.php">mailing lists</A> |
  <A href="http://us2.php.net/license">licenses</A> |
  <A href="http://wiki.php.net/">wiki</A> |
  <A href="http://bugs.php.net/">reporting bugs</A> |
  <A href="http://us2.php.net/sites.php">php.net sites</A> |
  <A href="http://us2.php.net/links.php">links</A> |
  <A href="http://us2.php.net/conferences/">conferences</A> |
  <A href="http://us2.php.net/my.php">my php.net</A>
 </DIV>
</DIV>

<DIV id="headsearch">
 <FORM method="post" action="http://us2.php.net/search.php" id="topsearch">
  <P>
   <SPAN title="Keyboard shortcut: Alt+S (Win), Ctrl+S (Apple)">
    <SPAN class="shortkey">s</SPAN>earch for
   </SPAN>
   <INPUT type="text" name="pattern" value="" size="30" accesskey="s">
   <SPAN>in the</SPAN>
   <SELECT name="show">
    <OPTION value="all">all php.net sites</OPTION>
    <OPTION value="local">this mirror only</OPTION>
    <OPTION value="quickref" selected="selected">function list</OPTION>
    <OPTION value="manual">online documentation</OPTION>
    <OPTION value="bugdb">bug database</OPTION>
    <OPTION value="news_archive">Site News Archive</OPTION>
    <OPTION value="changelogs">All Changelogs</OPTION>
    <OPTION value="pear">just pear.php.net</OPTION>
    <OPTION value="pecl">just pecl.php.net</OPTION>
    <OPTION value="talks">just talks.php.net</OPTION>
    <OPTION value="maillist">general mailing list</OPTION>
    <OPTION value="devlist">developer mailing list</OPTION>
    <OPTION value="phpdoc">documentation mailing list</OPTION>
   </SELECT>
   <INPUT type="image" src="./PHP_odbc_connect - Manual_files/small_submit_white.gif" class="submit" alt="search">
   <INPUT type="hidden" name="lang" value="en">
  </P>
 </FORM>
</DIV>

<DIV id="layout_2">
 <DIV id="leftbar">
<!--UdmComment-->
<UL class="toc">
 <LI class="header home"><A href="http://us2.php.net/manual/en/index.php">PHP Manual</A></LI>
 <LI class="header up"><A href="http://us2.php.net/manual/en/funcref.php">Function Reference</A></LI>
 <LI class="header up"><A href="http://us2.php.net/manual/en/refs.database.php">Database Extensions</A></LI>
 <LI class="header up"><A href="http://us2.php.net/manual/en/refs.database.abstract.php">Abstraction Layers</A></LI>
 <LI class="header up"><A href="http://us2.php.net/manual/en/book.uodbc.php">ODBC (Unified)</A></LI>
 <LI class="header up"><A href="http://us2.php.net/manual/en/ref.uodbc.php">ODBC Functions</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-autocommit.php">odbc_<SPAN class="w"> </SPAN>autocommit</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-binmode.php">odbc_<SPAN class="w"> </SPAN>binmode</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-close-all.php">odbc_<SPAN class="w"> </SPAN>close_<SPAN class="w"> </SPAN>all</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-close.php">odbc_<SPAN class="w"> </SPAN>close</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-columnprivileges.php">odbc_<SPAN class="w"> </SPAN>columnprivileges</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-columns.php">odbc_<SPAN class="w"> </SPAN>columns</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-commit.php">odbc_<SPAN class="w"> </SPAN>commit</A></LI>
 <LI class="active"><A href="./PHP_odbc_connect - Manual_files/PHP_odbc_connect - Manual.htm">odbc_<SPAN class="w"> </SPAN>connect</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-cursor.php">odbc_<SPAN class="w"> </SPAN>cursor</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-data-source.php">odbc_<SPAN class="w"> </SPAN>data_<SPAN class="w"> </SPAN>source</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-do.php">odbc_<SPAN class="w"> </SPAN>do</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-error.php">odbc_<SPAN class="w"> </SPAN>error</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-errormsg.php">odbc_<SPAN class="w"> </SPAN>errormsg</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-exec.php">odbc_<SPAN class="w"> </SPAN>exec</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-execute.php">odbc_<SPAN class="w"> </SPAN>execute</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-fetch-array.php">odbc_<SPAN class="w"> </SPAN>fetch_<SPAN class="w"> </SPAN>array</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-fetch-into.php">odbc_<SPAN class="w"> </SPAN>fetch_<SPAN class="w"> </SPAN>into</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-fetch-object.php">odbc_<SPAN class="w"> </SPAN>fetch_<SPAN class="w"> </SPAN>object</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-fetch-row.php">odbc_<SPAN class="w"> </SPAN>fetch_<SPAN class="w"> </SPAN>row</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-field-len.php">odbc_<SPAN class="w"> </SPAN>field_<SPAN class="w"> </SPAN>len</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-field-name.php">odbc_<SPAN class="w"> </SPAN>field_<SPAN class="w"> </SPAN>name</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-field-num.php">odbc_<SPAN class="w"> </SPAN>field_<SPAN class="w"> </SPAN>num</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-field-precision.php">odbc_<SPAN class="w"> </SPAN>field_<SPAN class="w"> </SPAN>precision</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-field-scale.php">odbc_<SPAN class="w"> </SPAN>field_<SPAN class="w"> </SPAN>scale</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-field-type.php">odbc_<SPAN class="w"> </SPAN>field_<SPAN class="w"> </SPAN>type</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-foreignkeys.php">odbc_<SPAN class="w"> </SPAN>foreignkeys</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-free-result.php">odbc_<SPAN class="w"> </SPAN>free_<SPAN class="w"> </SPAN>result</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-gettypeinfo.php">odbc_<SPAN class="w"> </SPAN>gettypeinfo</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-longreadlen.php">odbc_<SPAN class="w"> </SPAN>longreadlen</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-next-result.php">odbc_<SPAN class="w"> </SPAN>next_<SPAN class="w"> </SPAN>result</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-num-fields.php">odbc_<SPAN class="w"> </SPAN>num_<SPAN class="w"> </SPAN>fields</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-num-rows.php">odbc_<SPAN class="w"> </SPAN>num_<SPAN class="w"> </SPAN>rows</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-pconnect.php">odbc_<SPAN class="w"> </SPAN>pconnect</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-prepare.php">odbc_<SPAN class="w"> </SPAN>prepare</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-primarykeys.php">odbc_<SPAN class="w"> </SPAN>primarykeys</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-procedurecolumns.php">odbc_<SPAN class="w"> </SPAN>procedurecolumns</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-procedures.php">odbc_<SPAN class="w"> </SPAN>procedures</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-result-all.php">odbc_<SPAN class="w"> </SPAN>result_<SPAN class="w"> </SPAN>all</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-result.php">odbc_<SPAN class="w"> </SPAN>result</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-rollback.php">odbc_<SPAN class="w"> </SPAN>rollback</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-setoption.php">odbc_<SPAN class="w"> </SPAN>setoption</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-specialcolumns.php">odbc_<SPAN class="w"> </SPAN>specialcolumns</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-statistics.php">odbc_<SPAN class="w"> </SPAN>statistics</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-tableprivileges.php">odbc_<SPAN class="w"> </SPAN>tableprivileges</A></LI>
 <LI><A href="http://us2.php.net/manual/en/function.odbc-tables.php">odbc_<SPAN class="w"> </SPAN>tables</A></LI>
</UL><!--/UdmComment-->

 </DIV>
 <DIV id="content" class="manual/en">
<!--UdmComment-->
<DIV class="manualnavbar manualnavbar_top">
 <SPAN class="next">
  <A href="http://us2.php.net/manual/en/function.odbc-cursor.php">odbc_cursor<IMG src="./PHP_odbc_connect - Manual_files/caret-r.gif" alt="&gt;" width="11" height="7"></A>
 </SPAN>
 <SPAN class="prev">
  <A href="http://us2.php.net/manual/en/function.odbc-commit.php"><IMG src="./PHP_odbc_connect - Manual_files/caret-l.gif" alt="&lt;" width="11" height="7">odbc_commit</A>
 </SPAN>
 <HR>
 <SPAN class="lastupdated">Last updated: Fri, 05 Mar 2010</SPAN>
 <DIV class="langchooser">
  <FORM action="http://us2.php.net/manual/change.php" method="get">
   <P>view this page in </P><FIELDSET><SELECT name="page">
    <OPTION value="bg/function.odbc-connect.php">Bulgarian</OPTION>
    <OPTION value="pt_BR/function.odbc-connect.php">Brazilian Portuguese</OPTION>
    <OPTION value="fr/function.odbc-connect.php">French</OPTION>
    <OPTION value="de/function.odbc-connect.php">German</OPTION>
    <OPTION value="ja/function.odbc-connect.php">Japanese</OPTION>
    <OPTION value="kr/function.odbc-connect.php">Korean</OPTION>
    <OPTION value="pl/function.odbc-connect.php">Polish</OPTION>
    <OPTION value="ro/function.odbc-connect.php">Romanian</OPTION>
    <OPTION value="tr/function.odbc-connect.php">Turkish</OPTION>
    <OPTION value="help-translate.php">Other</OPTION>
   </SELECT>
   <INPUT type="image" src="./PHP_odbc_connect - Manual_files/small_submit.gif" id="changeLangImage" alt="Change language">
  </FIELDSET></FORM>
 </DIV>
</DIV>
<!--/UdmComment-->

<DIV id="function.odbc-connect" class="refentry">
 <DIV class="refnamediv">
  <H1 class="refname">odbc_connect</H1>
  <P class="verinfo">(PHP 4, PHP 5)</P><P class="refpurpose"><SPAN class="refname">odbc_connect</SPAN> — <SPAN class="dc-title">Connect to a datasource</SPAN></P>

 </DIV>
 
 <A name="function.odbc-connect.description"></A><DIV class="refsect1 description"><DIV class="reportbug"><A href="http://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=function.odbc-connect%23Description">Report a bug</A></DIV>
  <H3 class="title"><A class="toggler shown" href="http://us2.php.net/manual/en/function.odbc-connect.php#"><IMG src="./PHP_odbc_connect - Manual_files/notes-reject.gif"></A> Description</H3>
  <DIV class="methodsynopsis dc-description">
   <SPAN class="type">resource</SPAN> <SPAN class="methodname"><B>odbc_connect</B></SPAN>
    ( <SPAN class="methodparam"><SPAN class="type">string</SPAN> <TT class="parameter">$dsn</TT></SPAN>
   , <SPAN class="methodparam"><SPAN class="type">string</SPAN> <TT class="parameter">$user</TT></SPAN>
   , <SPAN class="methodparam"><SPAN class="type">string</SPAN> <TT class="parameter">$password</TT></SPAN>
   [, <SPAN class="methodparam"><SPAN class="type">int</SPAN> <TT class="parameter">$cursor_type</TT></SPAN>
  ] )</DIV>

  <P class="simpara">
   The connection id returned by this functions is needed by other
   ODBC functions. You can have multiple connections open at once as long as
   they either use different db or different credentials.
  </P>
  <P class="simpara">
   With some ODBC drivers, executing a complex stored procedure may
   fail with an error similar to: "Cannot open a cursor on a stored
   procedure that has anything other than a single select statement
   in it".  Using SQL_CUR_USE_ODBC may avoid that error. Also, some
   drivers don't support the optional row_number parameter in
   <A href="http://us2.php.net/manual/en/function.odbc-fetch-row.php" class="function">odbc_fetch_row()</A>. SQL_CUR_USE_ODBC might help
   in that case, too.
  </P>
 </DIV>


 <A name="function.odbc-connect.parameters"></A><DIV class="refsect1 parameters"><DIV class="reportbug"><A href="http://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=function.odbc-connect%23Parameters">Report a bug</A></DIV>
  <H3 class="title"><A class="toggler shown" href="http://us2.php.net/manual/en/function.odbc-connect.php#"><IMG src="./PHP_odbc_connect - Manual_files/notes-reject.gif"></A> Parameters</H3>
  <P class="para">
   </P><DL>

    <DT class="varlistentry">

     <SPAN class="term"><I><TT class="parameter">dsn</TT></I>
</SPAN>

     </DT><DD class="listitem">

      <P class="para">
       The database source name for the connection. Alternatively, a
       DNS-less connection string can be used.
      </P>
     </DD>

    
    <DT class="varlistentry">

     <SPAN class="term"><I><TT class="parameter">user</TT></I>
</SPAN>

     </DT><DD class="listitem">

      <P class="para">
       The username.
      </P>
     </DD>

    
    <DT class="varlistentry">

     <SPAN class="term"><I><TT class="parameter">password</TT></I>
</SPAN>

     </DT><DD class="listitem">

      <P class="para">
       The password.
      </P>
     </DD>

    
    <DT class="varlistentry">

     <SPAN class="term"><I><TT class="parameter">cursor_type</TT></I>
</SPAN>

     </DT><DD class="listitem">

      <P class="para">
       This sets the type of cursor to be used
       for this connection. This parameter is not normally needed, but
       can be useful for working around problems with some ODBC drivers.
      </P>
      <SPAN class="simpara">
       The following constants are defined for cursortype:
      </SPAN>
      <P class="para">
       </P><UL class="itemizedlist">
        <LI class="listitem">
         <SPAN class="simpara">
          SQL_CUR_USE_IF_NEEDED
         </SPAN>
        </LI>
        <LI class="listitem">
         <SPAN class="simpara">
          SQL_CUR_USE_ODBC
         </SPAN>
        </LI>
        <LI class="listitem">
         <SPAN class="simpara">
          SQL_CUR_USE_DRIVER
         </SPAN>
        </LI>
        <LI class="listitem">
         <SPAN class="simpara">
          SQL_CUR_DEFAULT
         </SPAN>
        </LI>
       </UL><P>
      </P>
     </DD>

    
   </DL>
<P>
  </P>
 </DIV>


 <A name="function.odbc-connect.returnvalues"></A><DIV class="refsect1 returnvalues"><DIV class="reportbug"><A href="http://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=function.odbc-connect%23Return%20Values">Report a bug</A></DIV>
  <H3 class="title"><A class="toggler shown" href="http://us2.php.net/manual/en/function.odbc-connect.php#"><IMG src="./PHP_odbc_connect - Manual_files/notes-reject.gif"></A> Return Values</H3>
  <P class="para">
   Returns an ODBC connection id or 0 (<B><TT class="constant">FALSE</TT></B>) on
   error.
  </P>
 </DIV>


 <A name="function.odbc-connect.examples"></A><DIV class="refsect1 examples"><DIV class="reportbug"><A href="http://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=function.odbc-connect%23Examples">Report a bug</A></DIV>
  <H3 class="title"><A class="toggler shown" href="http://us2.php.net/manual/en/function.odbc-connect.php#"><IMG src="./PHP_odbc_connect - Manual_files/notes-reject.gif"></A> Examples</H3>
  <P class="para">
   </P><DIV class="example">
    <P><B>Example #1 DNS-less connections</B></P>
    <DIV class="example-contents programlisting">
<DIV class="phpcode"><CODE><SPAN style="color: #000000">
<SPAN style="color: #0000BB">&lt;?php<BR></SPAN><SPAN style="color: #FF8000">//&nbsp;Microsoft&nbsp;SQL&nbsp;Server&nbsp;using&nbsp;the&nbsp;SQL&nbsp;Native&nbsp;Client&nbsp;10.0&nbsp;ODBC&nbsp;Driver&nbsp;-&nbsp;allows&nbsp;connection&nbsp;to&nbsp;SQL&nbsp;7,&nbsp;2000,&nbsp;2005&nbsp;and&nbsp;2008<BR></SPAN><SPAN style="color: #0000BB">$connection&nbsp;</SPAN><SPAN style="color: #007700">=&nbsp;</SPAN><SPAN style="color: #0000BB">odbc_connect</SPAN><SPAN style="color: #007700">(</SPAN><SPAN style="color: #DD0000">"Driver={SQL&nbsp;Server&nbsp;Native&nbsp;Client&nbsp;10.0};Server=</SPAN><SPAN style="color: #0000BB">$server</SPAN><SPAN style="color: #DD0000">;Database=</SPAN><SPAN style="color: #0000BB">$database</SPAN><SPAN style="color: #DD0000">;"</SPAN><SPAN style="color: #007700">,&nbsp;</SPAN><SPAN style="color: #0000BB">$user</SPAN><SPAN style="color: #007700">,&nbsp;</SPAN><SPAN style="color: #0000BB">$password</SPAN><SPAN style="color: #007700">);<BR><BR></SPAN><SPAN style="color: #FF8000">//&nbsp;Microsoft&nbsp;Access<BR></SPAN><SPAN style="color: #0000BB">$connection&nbsp;</SPAN><SPAN style="color: #007700">=&nbsp;</SPAN><SPAN style="color: #0000BB">odbc_connect</SPAN><SPAN style="color: #007700">(</SPAN><SPAN style="color: #DD0000">"Driver={Microsoft&nbsp;Access&nbsp;Driver&nbsp;(*.mdb)};Dbq=</SPAN><SPAN style="color: #0000BB">$mdbFilename</SPAN><SPAN style="color: #DD0000">"</SPAN><SPAN style="color: #007700">,&nbsp;</SPAN><SPAN style="color: #0000BB">$user</SPAN><SPAN style="color: #007700">,&nbsp;</SPAN><SPAN style="color: #0000BB">$password</SPAN><SPAN style="color: #007700">);<BR><BR></SPAN><SPAN style="color: #FF8000">//&nbsp;Microsoft&nbsp;Excel<BR></SPAN><SPAN style="color: #0000BB">$excelFile&nbsp;</SPAN><SPAN style="color: #007700">=&nbsp;</SPAN><SPAN style="color: #0000BB">realpath</SPAN><SPAN style="color: #007700">(</SPAN><SPAN style="color: #DD0000">'C:/ExcelData.xls'</SPAN><SPAN style="color: #007700">);<BR></SPAN><SPAN style="color: #0000BB">$excelDir&nbsp;</SPAN><SPAN style="color: #007700">=&nbsp;</SPAN><SPAN style="color: #0000BB">dirname</SPAN><SPAN style="color: #007700">(</SPAN><SPAN style="color: #0000BB">$excelFile</SPAN><SPAN style="color: #007700">);<BR></SPAN><SPAN style="color: #0000BB">$connection&nbsp;</SPAN><SPAN style="color: #007700">=&nbsp;</SPAN><SPAN style="color: #0000BB">odbc_connect</SPAN><SPAN style="color: #007700">(</SPAN><SPAN style="color: #DD0000">"Driver={Microsoft&nbsp;Excel&nbsp;Driver&nbsp;(*.xls)};DriverId=790;Dbq=</SPAN><SPAN style="color: #0000BB">$excelFile</SPAN><SPAN style="color: #DD0000">;DefaultDir=</SPAN><SPAN style="color: #0000BB">$excelDir</SPAN><SPAN style="color: #DD0000">"&nbsp;</SPAN><SPAN style="color: #007700">,&nbsp;</SPAN><SPAN style="color: #DD0000">''</SPAN><SPAN style="color: #007700">,&nbsp;</SPAN><SPAN style="color: #DD0000">''</SPAN><SPAN style="color: #007700">);<BR></SPAN><SPAN style="color: #0000BB">?&gt;</SPAN>
</SPAN>
</CODE></DIV>
    </DIV>

   </DIV><P>
  </P>
 </DIV>


 <A name="function.odbc-connect.seealso"></A><DIV class="refsect1 seealso"><DIV class="reportbug"><A href="http://bugs.php.net/report.php?bug_type=Documentation+problem&manpage=function.odbc-connect%23See%20Also">Report a bug</A></DIV>
  <H3 class="title"><A class="toggler shown" href="http://us2.php.net/manual/en/function.odbc-connect.php#"><IMG src="./PHP_odbc_connect - Manual_files/notes-reject.gif"></A> See Also</H3>
  <P class="para">
   </P><UL class="simplelist">
    <LI class="member">For persistent connections: <A href="http://us2.php.net/manual/en/function.odbc-pconnect.php" class="function" rel="rdfs-seeAlso">odbc_pconnect()</A> - Open a persistent database connection</LI>
   </UL><P>
  </P>
 </DIV>


</DIV><BR><BR><!--UdmComment-->
<DIV class="manualnavbar manualnavbar_bottom">
 <SPAN class="next">
  <A href="http://us2.php.net/manual/en/function.odbc-cursor.php">odbc_cursor<IMG src="./PHP_odbc_connect - Manual_files/caret-r.gif" alt="&gt;" width="11" height="7"></A>
 </SPAN>
 <SPAN class="prev">
  <A href="http://us2.php.net/manual/en/function.odbc-commit.php"><IMG src="./PHP_odbc_connect - Manual_files/caret-l.gif" alt="&lt;" width="11" height="7">odbc_commit</A>
 </SPAN>
 <HR>
 <SPAN class="lastupdated">Last updated: Fri, 05 Mar 2010</SPAN>
 <DIV class="langchooser">
  &nbsp;
 </DIV>
</DIV>
<!--/UdmComment-->


<DIV id="usernotes">
 <DIV class="head"><A class="toggler shown" href="http://us2.php.net/manual/en/function.odbc-connect.php#"><IMG src="./PHP_odbc_connect - Manual_files/notes-reject.gif"></A> 
  <SPAN class="action"><A href="http://us2.php.net/manual/add-note.php?sect=function.odbc-connect&redirect=http://us2.php.net/manual/en/function.odbc-connect.php"><IMG src="./PHP_odbc_connect - Manual_files/notes-add.gif" alt="add a note" width="13" height="13" class="middle"></A> <SMALL><A href="http://us2.php.net/manual/add-note.php?sect=function.odbc-connect&redirect=http://us2.php.net/manual/en/function.odbc-connect.php">add a note</A></SMALL></SPAN>
  <SMALL>User Contributed Notes</SMALL><BR>
  <STRONG>odbc_connect</STRONG>
 </DIV><DIV id="allnotes">
 <A name="96265"></A>
 <DIV class="note">
  <STRONG>ewilde aht bsmdevelopment dawt com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#96265">17-Feb-2010 09:08</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Once you've set up a UnixODBC connection to Informix (as described elsewhere, for example in <A href="http://www.unixodbc.org/" rel="nofollow" target="_blank">http://www.unixodbc.org/</A>), the following PHP code will access a database via its DSN:<BR>
<BR>
<SPAN class="default">&lt;?php<BR>
</SPAN><SPAN class="comment">// We must set these environment variables for Informix to work.&nbsp; Either<BR>
// do it here or in php.ini.<BR>
</SPAN><SPAN class="default">putenv</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"INFORMIXDIR=/usr/share/informix"</SPAN><SPAN class="keyword">);<BR>
</SPAN><SPAN class="default">putenv</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"ODBCINI=/usr/local/unixODBC/etc/odbc.ini"</SPAN><SPAN class="keyword">);<BR>
<BR>
</SPAN><SPAN class="comment">// Open up a connection to the database.<BR>
</SPAN><SPAN class="keyword">if (!(</SPAN><SPAN class="default">$con </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"CollectOh"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">""</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">""</SPAN><SPAN class="keyword">)))<BR>
&nbsp; echo </SPAN><SPAN class="string">"&lt;p&gt;Connection to CollectOh failed.&lt;/p&gt;\n"</SPAN><SPAN class="keyword">;<BR>
else<BR>
&nbsp; {<BR>
&nbsp; </SPAN><SPAN class="comment">// Let's try enumerating all of the tables in the database (there ain't<BR>
&nbsp; // no "show tables" here).<BR>
&nbsp; </SPAN><SPAN class="keyword">if ((</SPAN><SPAN class="default">$res </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_exec</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$con</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"select * from SYSTABLES"</SPAN><SPAN class="keyword">)))<BR>
&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp;&nbsp; echo </SPAN><SPAN class="string">"&lt;p&gt;\n"</SPAN><SPAN class="keyword">;<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">odbc_result_all</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$res</SPAN><SPAN class="keyword">);<BR>
&nbsp;&nbsp;&nbsp; echo </SPAN><SPAN class="string">"&lt;/p&gt;\n"</SPAN><SPAN class="keyword">;<BR>
&nbsp;&nbsp;&nbsp; }<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Close up shop, like good dobies.<BR>
&nbsp; </SPAN><SPAN class="default">odbc_close</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$con</SPAN><SPAN class="keyword">);<BR>
&nbsp; }<BR>
</SPAN><SPAN class="default">?&gt;</SPAN>
</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="95108"></A>
 <DIV class="note">
  <STRONG>Mika</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#95108">14-Dec-2009 09:26</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To connect a SQLite database in Linux I used the following function call<BR>
<BR>
<SPAN class="default">&lt;?php $db </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">'Driver=SQLite3;Database=' </SPAN><SPAN class="keyword">. </SPAN><SPAN class="default">Database</SPAN><SPAN class="keyword">::</SPAN><SPAN class="default">DATABASE</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">) or die(</SPAN><SPAN class="string">'could not open database!'</SPAN><SPAN class="keyword">); </SPAN><SPAN class="default">?&gt;<BR>
</SPAN><BR>
In Debian or Ubuntu package libsqliteodbc is requried. Check /etc/odbc.ini and /etc/odbcinst.ini.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="94257"></A>
 <DIV class="note">
  <STRONG>Shyam Hazari</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#94257">25-Oct-2009 11:43</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Here is my successful odbc_connect with mysql on Ubuntu. It took me a while to figure this out. <BR>
<BR>
Installed following packages using apt-get.<BR>
<BR>
apache2<BR>
apache2-mpm-prefork<BR>
apache2-utils<BR>
apache2.2-common<BR>
libapache2-mod-php5<BR>
libdbd-mysql-perl<BR>
libmyodbc<BR>
libmysqlclient15off<BR>
mysql-client-5.0<BR>
mysql-common<BR>
mysql-server-5.0<BR>
mysql-server-core-5.0<BR>
odbcinst1debian1<BR>
php5<BR>
php5-cli<BR>
php5-common<BR>
php5-odbc<BR>
unixodbc<BR>
<BR>
/etc/odbc.ini<BR>
------------<BR>
myodbc3&nbsp; &nbsp; &nbsp; = MySQL ODBC 3.51 Driver<BR>
<BR>
[myodbc3]<BR>
Driver&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; = /usr/lib/odbc/libmyodbc.so<BR>
Description&nbsp; = MySQL ODBC 3.51 Driver<BR>
Server&nbsp; &nbsp; &nbsp; &nbsp; = localhost<BR>
Port&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; = 3306<BR>
User&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; = shyam<BR>
Password&nbsp; &nbsp; = mypass<BR>
Database&nbsp; &nbsp; = mysql<BR>
Option&nbsp; &nbsp; &nbsp; &nbsp; = 3&nbsp;&nbsp; <BR>
Socket&nbsp; &nbsp; &nbsp;&nbsp; = /var/run/mysqld/mysqld.sock<BR>
<BR>
/etc/odbcinst.ini<BR>
----------------<BR>
[MySQL ODBC 3.51 Driver]<BR>
Description&nbsp; &nbsp; = MySQL driver<BR>
Driver&nbsp; &nbsp; &nbsp; &nbsp; = /usr/lib/odbc/libmyodbc.so<BR>
Setup&nbsp; &nbsp; &nbsp; &nbsp; = /usr/lib/odbc/libodbcmyS.so<BR>
CPTimeout&nbsp; &nbsp; = <BR>
CPReuse&nbsp; &nbsp; = <BR>
UsageCount&nbsp; &nbsp; = 1<BR>
<BR>
my php script<BR>
------------<BR>
<BR>
&lt;html&gt;<BR>
&lt;body&gt;<BR>
<SPAN class="default">&lt;?<BR>
$conn </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"DRIVER={MySQL ODBC 3.51 Driver};Server=localhost;Database=mysql"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"shyam"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"mypass"</SPAN><SPAN class="keyword">);<BR>
<BR>
</SPAN><SPAN class="default">$sql </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"SELECT user from user"</SPAN><SPAN class="keyword">;<BR>
</SPAN><SPAN class="default">$rs </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_exec</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$conn</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">$sql</SPAN><SPAN class="keyword">);<BR>
echo </SPAN><SPAN class="string">"&lt;table&gt;&lt;tr&gt;"</SPAN><SPAN class="keyword">;<BR>
echo </SPAN><SPAN class="string">"&lt;th&gt;User Name&lt;/th&gt;&lt;/tr&gt;"</SPAN><SPAN class="keyword">;<BR>
while (</SPAN><SPAN class="default">odbc_fetch_row</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">))<BR>
&nbsp;{<BR>
&nbsp;</SPAN><SPAN class="default">$user </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_result</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">"user"</SPAN><SPAN class="keyword">);<BR>
&nbsp;echo </SPAN><SPAN class="string">"&lt;tr&gt;&lt;td&gt;$user&lt;/td&gt;&lt;/tr&gt;"</SPAN><SPAN class="keyword">;<BR>
}<BR>
</SPAN><SPAN class="default">odbc_close</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$conn</SPAN><SPAN class="keyword">);<BR>
echo </SPAN><SPAN class="string">"&lt;/table&gt;"</SPAN><SPAN class="keyword">;<BR>
</SPAN><SPAN class="default">?&gt;<BR>
</SPAN><BR>
&lt;/body&gt;<BR>
&lt;/html&gt;</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="91967"></A>
 <DIV class="note">
  <STRONG>drew at pixelburn dot net</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#91967">03-Jul-2009 12:32</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified<BR>
<BR>
If you keep running&nbsp; into this on the 64 bit versions of windows, ie server 2008,&nbsp; and none of the other solutions helped.<BR>
<BR>
In a 64 bit windows server operating system, there are TWO odbc managers. When you pull up the usual menu for the odbc / dsn system, it is for the 64 bit odbc manager, and 32 bit applications (vb 6.0, PHP 5) will not work using these dsn's. <BR>
<BR>
This is where the 32 bit odbc manager is:<BR>
<BR>
C:\Windows\SysWOW64\odbcad32.exe</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="85869"></A>
 <DIV class="note">
  <STRONG>eisalen at yahoo dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#85869">22-Sep-2008 11:21</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
I've been having trouble displaying Russian characters from Access database using ODBC. You might try this solution, though it is using ADODB.Connection COM connection with added charset setting. 
<BR>

<BR>
<SPAN class="default">&lt;?php
<BR>
$db_connection </SPAN><SPAN class="keyword">= new </SPAN><SPAN class="default">COM</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"ADODB.Connection"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">NULL</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">1251</SPAN><SPAN class="keyword">);
<BR>
</SPAN><SPAN class="default">$db_connstr </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\DataDir\Employee.mdb;DefaultDir=C:\DataDir"</SPAN><SPAN class="keyword">;
<BR>

<BR>
</SPAN><SPAN class="default">$db_connection</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">open</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$db_connstr</SPAN><SPAN class="keyword">);
<BR>
</SPAN><SPAN class="default">$rs </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$db_connection</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">execute</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"SELECT EmpNameLocal, EmpPosLocal FROM tbl_Employee WHERE ID='$IDNo'"</SPAN><SPAN class="keyword">);
<BR>
</SPAN><SPAN class="default">$rs_fld0 </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Fields</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">0</SPAN><SPAN class="keyword">);
<BR>
</SPAN><SPAN class="default">$rs_fld1 </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Fields</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">1</SPAN><SPAN class="keyword">);
<BR>
while (!</SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">EOF</SPAN><SPAN class="keyword">) {
<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">$empNameLoc&nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$rs_fld0</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">value</SPAN><SPAN class="keyword">;
<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">$empWPPos&nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$rs_fld1</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">value</SPAN><SPAN class="keyword">;
<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">MoveNext</SPAN><SPAN class="keyword">();
<BR>
}
<BR>

<BR>
</SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Close</SPAN><SPAN class="keyword">();
<BR>
</SPAN><SPAN class="default">$db_connection</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Close</SPAN><SPAN class="keyword">();
<BR>
</SPAN><SPAN class="default">?&gt;</SPAN>
</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="85675"></A>
 <DIV class="note">
  <STRONG>Anonymous</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#85675">11-Sep-2008 08:16</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
This might be obvious to some, but here is a quick tidbit that might save you some time if you're using FreeTDS in Linux:<BR>
<BR>
Be sure that you have these two lines in freetds.conf:<BR>
dump file = /tmp/freetds.log<BR>
dump file append = yes<BR>
<BR>
so you can tail -f it in the background of debugging the problem.&nbsp; This helped me find my issue on on CentOS Linux:&nbsp; <BR>
&nbsp;<BR>
1) tsql test works<BR>
2) isql test works<BR>
3) odbc connection in php also works WHEN RUN FROM THE SHELL<BR>
4) running PHP through apache does NOT work.<BR>
<BR>
my /tmp/freetds.log file told me: <BR>
net.c:168:Connecting to MYDBSERVER port MYDBPORT<BR>
net.c:237:tds_open_socket: MYDBSERVER:MYDBPORT: Permission denied<BR>
<BR>
and the answer was my firewall/SELinux was denying the Apache processes access to connect to the remote MSSQL DB port, but my shell accounts were fine.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="83792"></A>
 <DIV class="note">
  <STRONG>Anonymous</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#83792">12-Jun-2008 03:08</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
I have used mdbtools to access .mdb file on my ubuntu box, as ODBC driver (and PHP)<BR>
It has very few features, and practically unusable.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="82105"></A>
 <DIV class="note">
  <STRONG>jared (who is at) hatwhite * com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#82105">27-Mar-2008 07:04</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
It is indeed possible to read the data stored in an MSAccess .mdb file while remaining entirely within Linux. It is thanks to the mdbtools project, which created an MDB driver for unix.<BR>
<BR>
Up to you to get PHP to move this data around. Here are the links to get you started:<BR>
<BR>
Documentation:<BR>
<A href="https://docs.google.com/viewer?url=ftp://kalamazoolinux.org/pub/pdf/dbaccess.pdf" rel="nofollow" target="_blank">ftp://kalamazoolinux.org/pub/pdf/dbaccess.pdf</A><BR>
<BR>
ODBC on Linux:<BR>
<A href="http://www.unixodbc.org/" rel="nofollow" target="_blank">http://www.unixodbc.org/</A><BR>
<BR>
MDB driver for the odbc system created above:<BR>
<A href="http://mdbtools.sourceforge.net/" rel="nofollow" target="_blank">http://mdbtools.sourceforge.net/</A><BR>
<BR>
Note that on most modern Linux boxen, you can bypass the (documented) command-line configuration and installation of these projects; simply use apt-get or some similar package installer.<BR>
<BR>
The documentation link covers more than the mdb driver and is a good place to start for all data access in Linux. Much thanks to the hard work which went into these three projects.<BR>
<BR>
-Jared</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="80873"></A>
 <DIV class="note">
  <STRONG>Ceeclipse</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#80873">05-Feb-2008 09:36</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
"Returns an ODBC connection id or 0 (FALSE) on error."<BR>
<BR>
Keep in mind that the following code in PHP5 will not work properly:<BR>
<BR>
<SPAN class="default">&lt;?php<BR>
<BR>
</SPAN><SPAN class="keyword">if( </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"test"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"test"</SPAN><SPAN class="keyword">, </SPAN><SPAN class="string">"test"</SPAN><SPAN class="keyword">) === </SPAN><SPAN class="default">false </SPAN><SPAN class="keyword">) {<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="comment">// Your error reporting/handling here..<BR>
</SPAN><SPAN class="keyword">}<BR>
<BR>
</SPAN><SPAN class="default">?&gt;<BR>
</SPAN><BR>
odbc_connect() returns an integer, and not a PHP5 boolean!</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="77920"></A>
 <DIV class="note">
  <STRONG>Kalle Sommer Nielsen</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#77920">20-Sep-2007 01:07</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
You may find lots of DSN strings at:<BR>
<A href="http://www.connectionstrings.com/" rel="nofollow" target="_blank">http://www.connectionstrings.com/</A></SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="77421"></A>
 <DIV class="note">
  <STRONG>stefanov at uk dot ibm dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#77421">29-Aug-2007 09:15</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
As a follow up to my previous post regarding "PHP get data from IBM Tivoli Netcool ObjectServer (Sybase database)", the link to the article has changed and is now:<BR>
<BR>
<A href="http://pimmy.co.uk/index.php/ObjectServer_PHP" rel="nofollow" target="_blank">http://pimmy.co.uk/index.php/ObjectServer_PHP</A><BR>
<BR>
Regards,<BR>
<BR>
Pimmy</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="72381"></A>
 <DIV class="note">
  <STRONG>exkludge at gmail dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#72381">17-Jan-2007 12:02</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
After doing "harald dot angel at gmail dot com" suggestion, you may still receive this error:<BR>
<BR>
"Warning: odbc_connect() [function.odbc-connect]: SQL error: [Microsoft][ODBC Microsoft Access Driver] The Microsoft Jet database engine cannot open the file '(unknown)'. It is already opened exclusively by another user, or you need permission to view its data., SQL state S1000 in SQLConnect in... "<BR>
<BR>
You may need to include the &lt;computer name&gt; of the machine where the ODBC is, to the &lt;local group&gt; of the machine where the *.mdb is stored. And make sure that the &lt;local group&gt; has enough permission to access the *.mdb.<BR>
<BR>
hope this make somebody more happy!<BR>
<BR>
more power to opensource.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="72214"></A>
 <DIV class="note">
  <STRONG>francesco_NO_SPAM_at_paladinux_dot_net</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#72214">08-Jan-2007 07:33</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
For connection to Informix database via ODBC, there are some problem (depending from the version of DB).<BR>
It's possible, if you have ver. 2.x or 3.x, than in insert query mode a double string, the server answer :<BR>
[Informix][Informix ODBC Driver][Informix]Character to numeric conversion error, SQL state 37000 in SQLExecDirect in server/page.php.<BR>
The only way to resolve the problem to resolve the problem is add the US-English locales to the PHP connection.<BR>
<BR>
Paladinux</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="71570"></A>
 <DIV class="note">
  <STRONG>harald dot angel at gmail dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#71570">06-Dec-2006 02:12</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
- Windows - OS<BR>
- Apache<BR>
- ODBC-Connction to MS-Access DB on a:<BR>
- Network Share<BR>
<BR>
After many hours searching here´s how it works:<BR>
<BR>
- Map the Network Drive where the mdb is located<BR>
- Setup System DSN in Control Panel with mapped Drive<BR>
- Open Registry at:<BR>
HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC_INI<BR>
- Edit the for example "M:\" to "\\server\..."<BR>
- Close Regedit<BR>
- The Apache-Service must run with a Domain (network)-User!!<BR>
- After that you can connect using:<BR>
<BR>
$conn = odbc_connect('your-dsn-name','',''); <BR>
<BR>
hope that makes someone happy :)<BR>
bye</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="71438"></A>
 <DIV class="note">
  <STRONG>Ray.Paseur sometimes uses GMail</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#71438">29-Nov-2006 03:48</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To connect and show tables in a Microsoft Access data base (created in *.asp pages)...<BR>
<BR>
$dbq&nbsp; &nbsp; =&nbsp; &nbsp; str_replace("/", "\\", $_SERVER["DOCUMENT_ROOT"]) . "\\path\\to\\database.mdb";<BR>
if&nbsp; &nbsp; (!file_exists($dbq)) { echo "Crap!&lt;br /&gt;No such file as $dbq"; }<BR>
<BR>
$db_connection = odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbq", "ADODB.Connection", "password", "SQL_CUR_USE_ODBC");<BR>
<BR>
$result = odbc_tables($db_connection);<BR>
<BR>
while (odbc_fetch_row($result)) {<BR>
&nbsp;&nbsp;&nbsp; if(odbc_result($result,"TABLE_TYPE")=="TABLE") {<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; echo "&lt;br /&gt;" . odbc_result($result,"TABLE_NAME");<BR>
&nbsp;&nbsp;&nbsp; }<BR>
}</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="71016"></A>
 <DIV class="note">
  <STRONG>stefanov at uk dot ibm dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#71016">08-Nov-2006 12:41</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Short tutorial on how to connect to the IBM Tivoli Netcool ObjectServer (based on Sybase):<BR>
<BR>
<A href="http://nuqm.micromuse.com/wiki/index.php/ObjectServer_PHP" rel="nofollow" target="_blank">http://nuqm.micromuse.com/wiki/index.php/ObjectServer_PHP</A><BR>
<BR>
Hopefully this will save some people precious time..<BR>
<BR>
Cheers,<BR>
Pimmy</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="68752"></A>
 <DIV class="note">
  <STRONG>sven dot delmeiren at cac dot be</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#68752">09-Aug-2006 02:39</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Hi,<BR>
<BR>
Instructions on how to connect to a Progress database on Linux using the Merant ODBC driver can be found at <A href="http://www.progteg.com/english/documents.html." rel="nofollow" target="_blank">http://www.progteg.com/english/documents.html.</A> <BR>
<BR>
Kind regards,<BR>
<BR>
Sven Delmeiren<BR>
Computers &amp; Communications NV</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="64159"></A>
 <DIV class="note">
  <STRONG>Kalle Sommer Nielsen</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#64159">09-Apr-2006 01:30</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To use MySQL via ODBC:<BR>
<SPAN class="default">&lt;?php<BR>
&nbsp;&nbsp;&nbsp; $db_host&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"server.mynetwork"</SPAN><SPAN class="keyword">;<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">$db_user&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"dbuser"</SPAN><SPAN class="keyword">;<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">$db_pass&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"dbpass"</SPAN><SPAN class="keyword">;<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">$dsn </SPAN><SPAN class="keyword">=&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"DRIVER={MySQL ODBC 3.51 Driver};" </SPAN><SPAN class="keyword">. <BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"CommLinks=tcpip(Host=$db_host);" </SPAN><SPAN class="keyword">. <BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"DatabaseName=$db_name;" </SPAN><SPAN class="keyword">. <BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"uid=$db_user; pwd=$db_pass"</SPAN><SPAN class="keyword">;<BR>
<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$dsn</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$db_user</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$db_pass</SPAN><SPAN class="keyword">);<BR>
</SPAN><SPAN class="default">?&gt;</SPAN>
</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="59413"></A>
 <DIV class="note">
  <STRONG>gekkeprutser at gmail dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#59413">06-Dec-2005 02:35</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
I also had a problem with this message: ([ODBC SQL Server driver]Allocation of a Sybase Open Client Context failed). The message only appeared after the server had run for a few hours, so I expected resource starvation. However it was a settings problem and I thought this might benefit others too.<BR>
<BR>
In addition to putting a <SPAN class="default">&lt;?php putenv </SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"SYBASE=c:\sybase"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="default">?&gt;</SPAN>&nbsp; as described by oottavi above, I also had so specify a locale by setting <SPAN class="default">&lt;?php putenv </SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"LC_ALL=default"</SPAN><SPAN class="keyword">); </SPAN><SPAN class="default">?&gt;</SPAN>.<BR>
<BR>
Even though my locale was already set to a valid one (en_US) I had to set this environment variable to make it work anyhow.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="56734"></A>
 <DIV class="note">
  <STRONG>owen at silicon-dream dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#56734">14-Sep-2005 03:07</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Connecting to an access database was as simple as the following line for me.<BR>
<BR>
odbc_connect("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . str_replace("/", "\\", $_SERVER["DOCUMENT_ROOT"]) . "\_database\dbname.mdb", "", "")</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="52556"></A>
 <DIV class="note">
  <STRONG>webmaster at dzconnexion dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#52556">05-May-2005 03:44</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Concerning the note posted by Grisu on the 23-Dec-2003 11:51: Connect to an MS-Access Database on the Network via ODBC,<BR>
<BR>
PLEASE dont forget to put double slashes as follows:<BR>
<BR>
"\\\\Server\\folder\\database.mdb" <BR>
<BR>
when setting up the registry key as indicated...</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="52401"></A>
 <DIV class="note">
  <STRONG>rotwhiler at hotmail dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#52401">29-Apr-2005 03:42</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
For anyone having problems with WHERE clauses in their MS Access ODBC requests here�s what I found: SQL requests sent to Access must include quotes around the criteria.<BR>
<BR>
$sel = "SELECT * FROM table1 WHERE cust_id = 'cust1'";<BR>
outputs:<BR>
SELECT * FROM table1 WHERE cust_id = 'cust1'<BR>
And works.<BR>
<BR>
$sel = �SELECT * FROM table1 WHERE cust_id = cust1�;<BR>
outputs:<BR>
SELECT * FROM table1 WHERE cust_id = cust1<BR>
And doesn�t work.<BR>
<BR>
Here�s the whole block of code:<BR>
$conn = odbc_connect("database1","","");<BR>
$sel = "SELECT * FROM table1 WHERE cust_id = 'cust1'";<BR>
$exec = odbc_exec($conn,$sel);<BR>
while($row = (odbc_fetch_array($exec)))<BR>
&nbsp;$serv[odbc_result($exec,'label')] = $row;<BR>
print_r($serv);</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="51420"></A>
 <DIV class="note">
  <STRONG>aurelien marchand</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#51420">30-Mar-2005 03:54</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
For three days I fought to be able to connect our Linux intranet server to our AS400 database through ODBC and PHP on Mandrake. I installed everything I thought would work but I still got a: odbc_connect(): SQL error: Missing server name, port, or database name in call to CC_connect., SQL state IM002 in SQLConnect<BR>
<BR>
Note that isql was working great but php was failing to connect.<BR>
<BR>
The solution:<BR>
I located and found a PHP module called php-unixODBC (to oppose with php-odbc). Once installed (even though it wasn't for the right version of PHP), I realised it didn't place the file properly. The ini file was in /etc/php/ instead of /etc/php.d/, so I moved it there and renamed the old /etc/php.d/36_odbc.ini to /etc/php.d/36_odbc.ini.sav, so that I now had /etc/php.d/36_unixodbc.ini. I restarted the httpd server and now I was able to access the as400.<BR>
<BR>
If you have questions, email _artaxerxes2_at_iname_dot_com (sans the underscore).</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="50861"></A>
 <DIV class="note">
  <STRONG>ramsosa at yahoo dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#50861">11-Mar-2005 07:47</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Connecting to ADS (Advantage Database Server) using Windows. When you setup data source in ODBC Manager (PHP_SERVER) don't use a mapped drive in Database or Data Dictionary Path, or you cannot connect:<BR>
<BR>
Lets suppose that you share C:\ADS_SERVER\ADS as ADS.<BR>
Mapping to a drive X: in PHP_SERVER<BR>
<BR>
Instead of:<BR>
<BR>
X:\APP\DATA\APP.ADD<BR>
<BR>
use UNC:<BR>
<BR>
\\ADS_SERVER\ADS\APP\DATA\APP.ADD<BR>
<BR>
if the ADS ODBC dialog don�t let you to browse a Network Drive type it manually</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="50571"></A>
 <DIV class="note">
  <STRONG>aamaral at 0kbps dot net</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#50571">03-Mar-2005 06:16</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Two additional notes regarding ODBC connections to a Network Sybase SQL Anywhere 8 Server..<BR>
<BR>
I wrote a script using the PHP5 CLI binary that monitors a directory for changes, then updates a Network Server SQL Anywhere 8 database when a change was detected. Idealy, my program would run indefinately, and issue odbc_connect()/odbc_close() when appropriate. However, it seems that once connected, your odbc session is limited to 30 seconds of active time, after which, the connection becomes stale, and no further queries can be executed.&nbsp; Instead, it returns a generic "Authentication violation"&nbsp; error from the odbc driver.<BR>
<BR>
Here's an example:<BR>
<BR>
<SPAN class="default">&lt;?php<BR>
&nbsp; $conn</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$connect_string</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">);<BR>
&nbsp; </SPAN><SPAN class="default">$result</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_exec</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$qry</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">$conn</SPAN><SPAN class="keyword">);&nbsp; </SPAN><SPAN class="comment">//returns data<BR>
&nbsp; </SPAN><SPAN class="default">sleep</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">31</SPAN><SPAN class="keyword">);<BR>
&nbsp; </SPAN><SPAN class="default">$result</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_exec</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$qry</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">$conn</SPAN><SPAN class="keyword">);&nbsp; </SPAN><SPAN class="comment">//"Authentication Violation"<BR>
</SPAN><SPAN class="default">?&gt;<BR>
</SPAN><BR>
Additionally, it seems that odbc_close() doesn't truely close the connection (at least not using Network SQL Anywhere 8). The resource is no longer usable after the odbc_close() is issued, but as far as the server is concerned, there is still a connection present. The connection doesn't truely close until after the php script has ended, which is unfortunate, because a subsequent odbc_connect() commands appear to reuse the existing stale connection, which was supposedly closed.<BR>
<BR>
My workaround was to design my script exit entirely after a the database update had completed.&nbsp; I then called my script whithin a batch file and put it inside an endless loop.<BR>
<BR>
I'm not sure if this is a bug with PHP or what, but I thought I'd share in case someone else is pulling their hair out trying to figure this one out...</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="50063"></A>
 <DIV class="note">
  <STRONG>aamaral at 0kbps dot net</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#50063">16-Feb-2005 08:29</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To connect to Sybase SQL Server Anywhere 8.0 on Windows use the following:<BR>
<BR>
<SPAN class="default">&lt;?php<BR>
</SPAN><SPAN class="comment">//================================================================<BR>
<BR>
&nbsp; // Configure connection parameters<BR>
&nbsp; </SPAN><SPAN class="default">$db_host&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"server.mynetwork"</SPAN><SPAN class="keyword">;<BR>
&nbsp; </SPAN><SPAN class="default">$db_server_name </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"Dev_Server"</SPAN><SPAN class="keyword">;<BR>
&nbsp; </SPAN><SPAN class="default">$db_name&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"Dev_Data"</SPAN><SPAN class="keyword">;<BR>
&nbsp; </SPAN><SPAN class="default">$db_file&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">'c:\dbstorage\dev.db'</SPAN><SPAN class="keyword">;<BR>
&nbsp; </SPAN><SPAN class="default">$db_conn_name&nbsp;&nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"php_script"</SPAN><SPAN class="keyword">;<BR>
&nbsp; </SPAN><SPAN class="default">$db_user&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"dbuser"</SPAN><SPAN class="keyword">;<BR>
&nbsp; </SPAN><SPAN class="default">$db_pass&nbsp; &nbsp; &nbsp; &nbsp; </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"dbpass"</SPAN><SPAN class="keyword">;<BR>
<BR>
</SPAN><SPAN class="comment">//================================================================<BR>
&nbsp; </SPAN><SPAN class="default">$connect_string </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"Driver={Adaptive Server Anywhere 8.0};"</SPAN><SPAN class="keyword">.<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"CommLinks=tcpip(Host=$db_host);"</SPAN><SPAN class="keyword">.<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"ServerName=$db_server_name;"</SPAN><SPAN class="keyword">.<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"DatabaseName=$db_name;"</SPAN><SPAN class="keyword">.<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"DatabaseFile=$db_file;"</SPAN><SPAN class="keyword">.<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"ConnectionName=$db_conn_name;"</SPAN><SPAN class="keyword">.<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; </SPAN><SPAN class="string">"uid=$db_user;pwd=$db_pass"</SPAN><SPAN class="keyword">;<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Connect to DB<BR>
&nbsp; </SPAN><SPAN class="default">$conn </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$connect_string</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">);<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Query<BR>
&nbsp; </SPAN><SPAN class="default">$qry </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"SELECT * FROM my_table"</SPAN><SPAN class="keyword">;<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Get Result<BR>
&nbsp; </SPAN><SPAN class="default">$result </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_exec</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$conn</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">$qry</SPAN><SPAN class="keyword">);<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Get Data From Result<BR>
&nbsp; </SPAN><SPAN class="keyword">while (</SPAN><SPAN class="default">$data</SPAN><SPAN class="keyword">[] = </SPAN><SPAN class="default">odbc_fetch_array</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$result</SPAN><SPAN class="keyword">));<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Free Result<BR>
&nbsp; </SPAN><SPAN class="default">odbc_free_result</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$result</SPAN><SPAN class="keyword">);<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Close Connection<BR>
&nbsp; </SPAN><SPAN class="default">odbc_close</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$conn</SPAN><SPAN class="keyword">);<BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">// Show data<BR>
&nbsp; </SPAN><SPAN class="default">print_r</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$data</SPAN><SPAN class="keyword">);<BR>
<BR>
</SPAN><SPAN class="comment">//================================================================<BR>
</SPAN><SPAN class="default">?&gt;</SPAN>
</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="47431"></A>
 <DIV class="note">
  <STRONG>manuel dot vecino at steria dot es</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#47431">16-Nov-2004 11:04</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Hi Mario, I changed a bit your script to suit my configuration,<BR>
I also included a lines to close the connection.<BR>
Thanks for the script<BR>
I am running apache 2.0.52 and PHP 5.0.2. Windows 2000<BR>
SQL 2000<BR>
<BR>
&lt;head&gt;<BR>
&lt;title&gt;Untitled Document&lt;/title&gt;<BR>
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;<BR>
&lt;/head&gt;<BR>
<BR>
&lt;body bgcolor="#FFFFFF"&gt;<BR>
&lt;table width="75%" border="1" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF"&gt;<BR>
&nbsp; &lt;tr bgcolor="#CCFFFF"&gt; <BR>
&nbsp;&nbsp;&nbsp; &lt;td height="22"&gt;&lt;b&gt;Tipo&lt;/b&gt;&lt;/td&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;td height="22"&gt;&lt;b&gt;Marca&lt;/b&gt;&lt;/td&gt;<BR>
&nbsp;&nbsp;&nbsp; &lt;td height="22"&gt;&lt;b&gt;Modelo&lt;/b&gt;&lt;/td&gt;<BR>
&nbsp; &lt;/tr&gt;<BR>
<BR>
<SPAN class="default">&lt;?php <BR>
$cx</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_pconnect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"RAMPANT"</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">"Invent"</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">"pass"</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">""</SPAN><SPAN class="keyword">); <BR>
</SPAN><SPAN class="default">$cur</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_exec</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$cx</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">"select tipo,marca,modelo from inv_equipos"</SPAN><SPAN class="keyword">); <BR>
while(</SPAN><SPAN class="default">odbc_fetch_row</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$cur</SPAN><SPAN class="keyword">))<BR>
{ <BR>
</SPAN><SPAN class="comment">//collect results<BR>
</SPAN><SPAN class="default">$tipo</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_result</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$cur</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">1</SPAN><SPAN class="keyword">); <BR>
</SPAN><SPAN class="default">$marca</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_result</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$cur</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">2</SPAN><SPAN class="keyword">); <BR>
</SPAN><SPAN class="default">$modelo</SPAN><SPAN class="keyword">=</SPAN><SPAN class="default">odbc_result</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$cur</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">3</SPAN><SPAN class="keyword">);<BR>
</SPAN><SPAN class="comment">//format and display results<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="keyword">print (</SPAN><SPAN class="string">"&lt;tr&gt;"</SPAN><SPAN class="keyword">);<BR>
&nbsp;&nbsp;&nbsp; print (</SPAN><SPAN class="string">"&lt;td&gt;$tipo&lt;/td&gt;"</SPAN><SPAN class="keyword">);<BR>
&nbsp;&nbsp;&nbsp; print (</SPAN><SPAN class="string">"&lt;td&gt;$marca&lt;/td&gt;"</SPAN><SPAN class="keyword">);<BR>
&nbsp;&nbsp;&nbsp; print (</SPAN><SPAN class="string">"&lt;td&gt;$modelo&lt;/td&gt;"</SPAN><SPAN class="keyword">);<BR>
&nbsp;&nbsp;&nbsp; print (</SPAN><SPAN class="string">"&lt;/tr&gt;"</SPAN><SPAN class="keyword">);<BR>
&nbsp;&nbsp;&nbsp; }<BR>
<BR>
</SPAN><SPAN class="comment">//disconnect from database<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">odbc_close</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$cx</SPAN><SPAN class="keyword">);<BR>
<BR>
&nbsp;&nbsp;&nbsp; </SPAN><SPAN class="default">?&gt;<BR>
</SPAN>&nbsp; &nbsp; <BR>
&nbsp; <BR>
&lt;/table&gt;<BR>
&lt;/body&gt;<BR>
&lt;/html&gt;</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="46565"></A>
 <DIV class="note">
  <STRONG>emin dot eralp at bg dot com dot tr</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#46565">15-Oct-2004 04:46</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
A VERY IMPORTANT NOTE OF CAUTION FOR WINDOWS USERS DEVELOPING ON NON-NETWORKED SYSTEMS<BR>
<BR>
If like me you are developing on a stand-alone system (Windows XP professional running IIS).&nbsp; Make sure that the the folder your database resides in is shared, otherwise you will get the following type of message:<BR>
<BR>
Current Recordset does not support updating. This may be a limitation of the provider, or of the selected locktype.' <BR>
<BR>
and you will spend 2 days (as I did) looking for the right combination of settings to write the record properly.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="43947"></A>
 <DIV class="note">
  <STRONG>f dot chehimi at lancaster dot ac dot uk  (Fadi)</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#43947">09-Jul-2004 08:13</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
This is the typical solution with the steps to follow if someone wants to connect MS Access to PHP. it took me a couple of hours actually till i reached it. i just wanted to ease the hassle for my colleagues in order not to waste their time as i did. this is the duty of every programmer towards his/her peers :p <BR>
here you are the CAKE :)<BR>
<BR>
<SPAN class="default">&lt;?php<BR>
<BR>
</SPAN><SPAN class="comment">// to have this working:<BR>
// 1- u&nbsp; have first to creat ur access database using MS <BR>
//&nbsp; &nbsp;&nbsp; Access&nbsp; (i asume u know how to do this). My database <BR>
//&nbsp; &nbsp;&nbsp; that i used in my example is called "Questionaire.mdb". <BR>
//&nbsp; &nbsp;&nbsp; the table in it is called "Results"<BR>
//<BR>
// 2- then u have to add this database to ODBC in the<BR>
//&nbsp; &nbsp;&nbsp; control panel.<BR>
//<BR>
// 3- the adition happens by adding "MS Access Driver" to the <BR>
//&nbsp; &nbsp;&nbsp; "System DNS" tab in ODBC Data Source Administrator. if <BR>
//&nbsp; &nbsp;&nbsp; u have that "MS Access Driver" in "User DNS" tab, then <BR>
//&nbsp; &nbsp;&nbsp; u have to delete it.<BR>
//<BR>
// 4- click on Add in the "System DNS" tab.<BR>
//<BR>
// 5- choose "MS Access Driver" from the "Creat New <BR>
//&nbsp; &nbsp;&nbsp; Database Source" window and click finish. <BR>
//<BR>
// 6- then the "ODBC MS Access Setup" window will pop-up.<BR>
//<BR>
// 7- give the driver the name that you want to use in your <BR>
//&nbsp; &nbsp;&nbsp; PHP scripting. i used here "MSAccessDriver".<BR>
<BR>
// 8- after this, choose the "Select" button in "ODBC MS <BR>
//&nbsp; &nbsp;&nbsp; Access Setup" to set the path of your Access database.<BR>
//<BR>
// 9-then u r done!!<BR>
<BR>
// this odbc_connect does the connection to the driver i <BR>
// created in the ODBC Administrator<BR>
</SPAN><SPAN class="default">$con </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">'MSAccessDriver'</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">,</SPAN><SPAN class="string">''</SPAN><SPAN class="keyword">);&nbsp; <BR>
<BR>
if (</SPAN><SPAN class="default">$con</SPAN><SPAN class="keyword">)<BR>
{<BR>
&nbsp; echo </SPAN><SPAN class="string">"odbc connected&lt;br&gt;"</SPAN><SPAN class="keyword">;<BR>
&nbsp; </SPAN><SPAN class="default">$sql </SPAN><SPAN class="keyword">=&nbsp; </SPAN><SPAN class="string">"select * from Results"</SPAN><SPAN class="keyword">; <BR>
<BR>
&nbsp; </SPAN><SPAN class="comment">//this function will execute the sql satametn in&nbsp;&nbsp; <BR>
&nbsp; //correspondance to the table in the db<BR>
&nbsp; </SPAN><SPAN class="default">$exc </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_exec</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$con</SPAN><SPAN class="keyword">,</SPAN><SPAN class="default">$sql</SPAN><SPAN class="keyword">);&nbsp;&nbsp; <BR>
}<BR>
else<BR>
&nbsp; echo </SPAN><SPAN class="string">"odbc not connected&lt;br&gt;"</SPAN><SPAN class="keyword">;<BR>
&nbsp;<BR>
if(</SPAN><SPAN class="default">$exc</SPAN><SPAN class="keyword">)<BR>
{<BR>
&nbsp; echo </SPAN><SPAN class="string">"selection completed&lt;br&gt;"</SPAN><SPAN class="keyword">;<BR>
&nbsp; while(</SPAN><SPAN class="default">$row </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_fetch_row</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$exc</SPAN><SPAN class="keyword">) )<BR>
&nbsp;&nbsp; &nbsp; &nbsp; echo </SPAN><SPAN class="default">$row</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">id</SPAN><SPAN class="keyword">.</SPAN><SPAN class="string">"&lt;br&gt;"</SPAN><SPAN class="keyword">;<BR>
}<BR>
else<BR>
&nbsp; echo </SPAN><SPAN class="string">"selection failed&lt;br&gt;"</SPAN><SPAN class="keyword">;<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; <BR>
</SPAN><SPAN class="default">?&gt;</SPAN>
</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="43475"></A>
 <DIV class="note">
  <STRONG>d-m at eudoramail dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#43475">22-Jun-2004 07:05</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/<BR>
Compiling Apache + PHP + DB2 8.1&nbsp; without the DATABASE instaled at the WebServer Machine!<BR>
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/<BR>
<BR>
Go to the machine that you have DB2 DATABASE instaled and COPY the include files from the DB2 8.1 DataBase to the PHP source directory:<BR>
<BR>
Sample:<BR>
[root@DB2_SERVER/usr/opt/db2_08_01/include]# scp * user@webserver:/usr/src/php-4.3.7/ext/odbc/.<BR>
<BR>
INSTALLING THE WEBSERVER!<BR>
Enter in the WebServer as root and ...<BR>
<BR>
-- DB2 --<BR>
Install Administration Client<BR>
Catalog the DataBases<BR>
-- END DB2 --<BR>
<BR>
-- LIB --<BR>
vi /etc/ld.so.conf<BR>
add line: /opt/IBM/db2/V8.1/lib<BR>
execute: ldconfig<BR>
-- END LIB --<BR>
<BR>
Download PHP + MODSSL + OPENSSL + APACHE!<BR>
<BR>
--- APACHE ---<BR>
cd ../mod_ssl-2.8.18-1.3.31<BR>
./configure&nbsp; --enable-module=so --with-apache=../apache_1.3.31 --with-ssl=../openssl-0.9.7d<BR>
cd ../apache_1.3.31/<BR>
make<BR>
make certificate TYPE=custom<BR>
make install<BR>
--- END APACHE ---<BR>
<BR>
OBS:&nbsp; CRIPT the CA.key<BR>
&nbsp;&nbsp;&nbsp; DO NOT CRYPT server.key<BR>
<BR>
-- PHP --<BR>
cd ../php-4.3.7<BR>
./configure&nbsp; --with-apxs=/usr/local/apache/bin/apxs --with-mysql --with-pgsql --with-zip=/usr/local/lib --with-ibm-db2=/opt/IBM/db2/V8.1<BR>
make<BR>
make install<BR>
-- END PHP ---<BR>
<BR>
-- APACHE EDIT TO RUN DB2 --<BR>
vim /usr/local/apache/bin/apachectl<BR>
add line: . /home/db2inst1/sqllib/db2profile<BR>
-- END APACHE EDIT TO RUN DB2 --<BR>
NOW run /usr/local/apache/bin/apachectl startssl<BR>
<BR>
DONE !!!!!<BR>
<BR>
You have a WebServer with PHP with DB2,MYSQL,POSTGRES and SSL Support. <BR>
<BR>
Enjoy IT!<BR>
<BR>
[]�s<BR>
Helio Ferenhof</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="42854"></A>
 <DIV class="note">
  <STRONG>simonr at no2sp at m dot cogapp dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#42854">01-Jun-2004 12:26</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To make a DSN-less connection using ODBC to MS-SQL:
<BR>

<BR>
<SPAN class="default">&lt;?php
<BR>

<BR>
$connection_string </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">'DRIVER={SQL Server};SERVER=&lt;servername&gt;;DATABASE=&lt;databasename&gt;'</SPAN><SPAN class="keyword">;
<BR>

<BR>
</SPAN><SPAN class="default">$user </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">'username'</SPAN><SPAN class="keyword">;
<BR>
</SPAN><SPAN class="default">$pass </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">'password'</SPAN><SPAN class="keyword">;
<BR>

<BR>
</SPAN><SPAN class="default">$connection </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">odbc_connect</SPAN><SPAN class="keyword">( </SPAN><SPAN class="default">$connection_string</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$user</SPAN><SPAN class="keyword">, </SPAN><SPAN class="default">$pass </SPAN><SPAN class="keyword">);
<BR>

<BR>
</SPAN><SPAN class="default">?&gt;
<BR>
</SPAN>
<BR>
servername is the name of the database server
<BR>

<BR>
databasename is the name of the database
<BR>

<BR>
Note, I've only tried this from a windows box using the Microsoft ODBC drivers.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="41135"></A>
 <DIV class="note">
  <STRONG>therebel at tiscali dot fr</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#41135">31-Mar-2004 03:06</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To connect to a MDB Access file without adding a system dsn to Windows :<BR>
<BR>
$cfg_dsn = "DRIVER=Microsoft Access Driver (*.mdb);<BR>
DBQ=C:/Access.mdb;<BR>
UserCommitSync=Yes;<BR>
Threads=3;<BR>
SafeTransactions=0;<BR>
PageTimeout=5;<BR>
MaxScanRows=8;<BR>
MaxBufferSize=2048;<BR>
DriverId=281;<BR>
DefaultDir=C:/ProgramFiles/CommonFiles/ODBC/DataSources";<BR>
<BR>
$cfg_dsn_login = "";<BR>
$cfg_dsn_mdp = "";<BR>
<BR>
odbc_connect($cfg_dsn,$cfg_dsn_login,$cfg_dsn_mdp);</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="40640"></A>
 <DIV class="note">
  <STRONG>sa_kelkar at yahoo dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#40640">10-Mar-2004 03:41</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
While Installing PHP&nbsp; + Apache + DB2 some time it give problem with odbc_connect(). . to solve this problem <BR>
<BR>
make sure that u have made following entry in /etc/ld.so.conf<BR>
<BR>
/usr/IBMdb2/V7.1/lib<BR>
/usr/IBMdb2/V7.1/include<BR>
/usr/lib<BR>
<BR>
please add following line on line no 25 in /etc/rc.d/init.d/httpd<BR>
<BR>
./home/db2inst1/sqllib/db2profile<BR>
(i.e /home/(instant name)/sqllib/db2profile<BR>
<BR>
for more detail please visit to IBM site<BR>
<BR>
it will work</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="39618"></A>
 <DIV class="note">
  <STRONG>atze at o2o dot com dot au</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#39618">04-Feb-2004 11:41</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To connect to a SQL DB on a unix srv via odbc one can use one of the following solutions.<BR>
<BR>
1. having an odbc.ini (~/.odbc.ini)<BR>
<BR>
[PostgreSQL]<BR>
Description&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; = PostgreSQL template1<BR>
Driver&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = PostgreSQL<BR>
Trace&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; = Yes<BR>
TraceFile&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; = /tmp/odbc.log<BR>
Database&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = PerfTest<BR>
Servername&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = localhost<BR>
UserName&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = boss<BR>
Password&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = BigBoss<BR>
Port&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 5432<BR>
Protocol&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = 6.4<BR>
ReadOnly&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = Yes<BR>
ConnSettings&nbsp; &nbsp; &nbsp; &nbsp; =<BR>
<BR>
[Default]<BR>
Driver = /local/lib/libodbc.so<BR>
<BR>
2. specifying a DSN <BR>
<BR>
function DBCALL($SQL)<BR>
{&nbsp; &nbsp; &nbsp; &nbsp; <BR>
$U = "boss";<BR>
$DB = "PerfTest";<BR>
$P = "BigBoss";<BR>
$Srv = "llocalhost";<BR>
$DSN = "Driver=PostgreSQL;Server=$Srv;Database=$DB";<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; <BR>
echo "Trying to connect to $DSN\n";&nbsp; &nbsp; <BR>
if ($CID = odbc_connect ("$DSN","$U","$P",SQL_CUR_USE_ODBC))<BR>
{<BR>
&nbsp;&nbsp;&nbsp; echo "still trying CID = $CID\n";<BR>
&nbsp;&nbsp;&nbsp; if ($RES = odbc_exec($CID, $SQL))<BR>
&nbsp;&nbsp;&nbsp; {<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; echo "RES = $RES\n";<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; print_r($RES);<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; echo "\n";<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; <BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; $NR = odbc_num_rows($RES);<BR>
<BR>
&lt;snip&gt;<BR>
<BR>
Hope this helps.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="38471"></A>
 <DIV class="note">
  <STRONG>Grisu</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#38471">23-Dec-2003 11:51</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Connect to an MS-Access Database on the Network via ODBC<BR>
<BR>
Apache 2.0.47 with PHP 4.3.4 running on Windows XP Pro<BR>
<BR>
If you encounter the error<BR>
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect"<BR>
<BR>
you should make sure to have the following done:<BR>
<BR>
The ODBC-link must be a System-DNS and not a User-DNS. Configure your ODBC-link and then modify your configuration with regedt32. Go to HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC_INI and open your ODBC-link. The field DBQ contains the path to your database. This path must be without Drive-names (e. g. "M:") so change it to "\\Server\folder\database.mdb". This setting is changed each time you modify your ODBC-configuration using the Windows-tool, so make sure you do this afterwards.<BR>
<BR>
Then you go to the Services-Section in your Systemmanagement. Select the properties of your Apache module. In the login-section you have to make sure you login with a valid User-Account for your Network-Server.<BR>
<BR>
Please note that this way you still have no permission to access linked tables within the linked database<BR>
<BR>
Funny enough all this is not necessary on Win98.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="37236"></A>
 <DIV class="note">
  <STRONG>TheFrenZ</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#37236">07-Nov-2003 12:22</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If you encounter the error:<BR>
<BR>
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect"<BR>
<BR>
Windows with PHP, running under IIS/PWS, PHP runs under the anonymous user, INET_USR_"server" (were "server" is your servername).<BR>
This user has no read access in the ODBC System DSN tree in the registry.<BR>
<BR>
With regedt32 open HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC_INI and give read access to every ODBC entry you want to use with PHP.<BR>
<BR>
Beware: With every change to a ODBC system DSN, the rights on that ODBC system DSN are gone again, and you have to change the rights again manualy.<BR>
<BR>
Under Apache, PHP runs under the System account and you wont have this problem.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="37055"></A>
 <DIV class="note">
  <STRONG>ivan21 at bol dot com dot br</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#37055">01-Nov-2003 04:28</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
The best source of information (for unix user), you can find here:<BR>
<BR>
<A href="http://www.unixodbc.org/" rel="nofollow" target="_blank">http://www.unixodbc.org/</A></SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="35331"></A>
 <DIV class="note">
  <STRONG>lffranco at dco.pemex.com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#35331">28-Aug-2003 01:08</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
As always Microsoft is clueless... I've been trying to connect to an Access database on a W2K on the network (not a local file, but mapped on the V: drive), via ODBC.<BR>
<BR>
All I got is this message:<BR>
Warning: SQL error: [Microsoft][ODBC Microsoft Access Driver] '(unknown)' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides., SQL state S1009 in SQLConnect in d:\apache\cm\creaart.php on line 13<BR>
<BR>
So... I started looking al around and looks like the ODBC driver has some severe problems:<BR>
<BR>
1. It cannot access a Access database via a mapped drive. And this is for ANY application, name it PHP, Coldfusion, whatever<BR>
2. You cannot make a system DSN with a UNC (\\Server\resource), so you must map the drive<BR>
<BR>
Cute isn't it?<BR>
<BR>
So... I quit on ODBC and went via ADO, this is the code that works:<BR>
<BR>
=== CODE ===<BR>
<BR>
$db = '\\\\server\\resource\\db.mdb';<BR>
$conn = new COM('ADODB.Connection');<BR>
$conn-&gt;Open("DRIVER={Driver do Microsoft Access (*.mdb)}; DBQ=$db");<BR>
<BR>
// Driver do Microsoft Access (*.mdb)<BR>
// must be the name in your odbc drivers, the one you get<BR>
// from the Data Sources (ODBC).<BR>
// In this case, I'm in Mexico but the driver name is in portuguese, thanks Microsoft.<BR>
<BR>
$sql = 'SELECT username FROM tblUsuarios';<BR>
$res = $conn-&gt;Execute($sql);<BR>
while (!$res-&gt;EOF)<BR>
{<BR>
&nbsp;&nbsp;&nbsp; print $res-&gt;Fields['username']-&gt;Value . "&lt;br&gt;";<BR>
&nbsp;&nbsp;&nbsp; $res-&gt;MoveNext();<BR>
}<BR>
<BR>
$res-&gt;Close(); <BR>
$conn-&gt;Close(); <BR>
$res = null; <BR>
$conn = null;<BR>
<BR>
=== /CODE ===</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="32539"></A>
 <DIV class="note">
  <STRONG>eric dot ramirez at iberoonline dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#32539">30-May-2003 05:44</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Connecting with SQL in a ODBC source<BR>
<BR>
2 ways, one is if your SQL server is runign in your machine<BR>
<BR>
$ser="LOCALMACHINE"; #the name of the SQL Server<BR>
$db="mydatabase"; #the name of the database<BR>
$user="myusername"; #a valid username<BR>
$pass="my pass"; #a password for the username<BR>
<BR>
# one line<BR>
$conn=odbc_connect("Driver={SQL Server};Server=".$ser.";Database=".$db,$user,$pass);<BR>
# one line<BR>
<BR>
the second way is if the SQL Server is runing in other machine but in the same network<BR>
<BR>
$ser="LOCALMACHINE"; #the name of the SQL Server<BR>
$db="mydatabase"; #the name of the database<BR>
$user="myusername"; #a valid username<BR>
$pass="my pass"; #a password for the username<BR>
<BR>
#one line<BR>
$conn=odbc_connect("DRIVER=SQL Server;SERVER=".$ser.";UID=".$user.";PWD=".$pass.";<BR>
DATABASE=".$db.";<BR>
Address=".$ser.",1433","","");<BR>
#one line</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="31745"></A>
 <DIV class="note">
  <STRONG>richard at lordrich dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#31745">02-May-2003 11:07</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Because the dsn needs to be system-wide, you will also need write access to the registry to set it up.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="30554"></A>
 <DIV class="note">
  <STRONG>Yvan Ecarri</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#30554">21-Mar-2003 11:01</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
I fighted with the "Data source name not found and no<BR>
default driver specified, SQL state IM002 in SQLConnect"<BR>
error for a while trying to connect via ODBC to a SQL Server<BR>
2000. Finally I found this workaround:<BR>
<BR>
$cn = odbc_connect("Driver={SQL Server};Server=MyServer;Database=MyDatabase",<BR>
"MyUser","MyPassword")<BR>
<BR>
Change "MyServer", "MyDatabase", "MyUser" and "MyPassword" to the right values.<BR>
<BR>
I guess that adding the "Integrated Security=YES" will work too.<BR>
<BR>
Regards,<BR>
<BR>
Yvan Ecarri, MCDBA, MCSD</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="29924"></A>
 <DIV class="note">
  <STRONG>jeremy at austin.ibm.com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#29924">28-Feb-2003 10:20</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
here's a quick note about using php and db2 that cost me a couple of hours and several recompiles trying to figure out why it didn't work.<BR>
<BR>
put the below line in any script<BR>
<BR>
&nbsp;&nbsp; &nbsp; putenv("DB2INSTANCE=db2inst1");<BR>
<BR>
Or, set that in your webserver environment somehow.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="27715"></A>
 <DIV class="note">
  <STRONG>sambou at everyonesports dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#27715">16-Dec-2002 10:11</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If you encounter the error:<BR>
<BR>
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect"<BR>
<BR>
make sure you have the correct permission to your database file (e.g. if using Win2k, might want to set the "Everyone" group to "Full Control").&nbsp; For Windows, I find that I have to sometimes use the registry editor (e.g. RegEdt32.exe) to set the database file's permission because for some unknown reason, setting the permission from the file's "Properties" option does not work.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="26610"></A>
 <DIV class="note">
  <STRONG>oottavi at netcourrier dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#26610">06-Nov-2002 06:36</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If you have problem to connect to sybase with an ODBC driver, try to set up your SYBASE environment variable to the correct directory. <BR>
([ODBC SQL Server driver]Allocation of a Sybase Open Client Context failed)<BR>
<BR>
Ex : Here is a connection to a DSN <BR>
<BR>
putenv("SYBASE=c:\sybase");<BR>
<BR>
$conn&nbsp; =&nbsp; odbc_connect("DSN1","USER","PASSWORD");<BR>
echo&nbsp; "conn:&nbsp; $conn";<BR>
if&nbsp; ($conn&nbsp; &lt;=&nbsp; 0)&nbsp; {<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; echo&nbsp; "Error&nbsp; in&nbsp; connection";<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; exit;<BR>
} else&nbsp; {<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; echo&nbsp; "&lt;P&gt;Connection&nbsp; successful\n";<BR>
};</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="26458"></A>
 <DIV class="note">
  <STRONG>mortoray at ecircle-ag dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#26458">31-Oct-2002 12:31</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If you have switched to a new Version of PHP (from 4.1 to 4.3) and at the same time have upgraded your Apache server (from 1.x to 2.x) and suddenly get the error:<BR>
<BR>
"[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect"<BR>
<BR>
It may be because you have your ODBC connections listed (Control Panel | ODBC) as User DSN rather than System DSN.&nbsp; They need to be System DSN in order for the PHP in the Apache service to access to them.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="23666"></A>
 <DIV class="note">
  <STRONG>osiris at rich-howard dot co dot uk</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#23666">24-Jul-2002 05:34</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Thought I'd add a note here on this. I'm using Apache 2.0.39 on Windows XP and PHP 4.2.2.<BR>
<BR>
It helps a lot if you don't use capital letters in your dsn string.<BR>
<BR>
Thought I also comment on the posts about using system dsns over file dsns. There are lots of posts saying use systems not files, but none (that I have seen) which explain why.<BR>
<BR>
Essentially: File DSNs are specific to the current user, therefore the Internet Guest User Account doesn't have rights to them. Systems are available to everyone.<BR>
<BR>
Regards<BR>
<BR>
Osiris :)</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="18777"></A>
 <DIV class="note">
  <STRONG>d-m at eudoramail dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#18777">05-Feb-2002 05:40</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/<BR>
odbc_connect ERRO at DB2<BR>
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/<BR>
<BR>
To Solve the problem with DB2 + PHP folow this steps!<BR>
<BR>
INSTALL THE PROGRAM LIKE THIS!<BR>
<BR>
-- DB2 --<BR>
Install the DataBank<BR>
Install Application Tools<BR>
-- END DB2 --<BR>
<BR>
--- APACHE ---<BR>
cd ../mod_ssl-2.8.5-1.3.22/<BR>
./configure&nbsp; --enable-module=so --with-apache=../apache_1.3.22/&nbsp; --with-ssl=../openssl-0.9.6c/<BR>
cd ../apache_1.3.22/<BR>
make<BR>
make certificate TYPE=custom<BR>
make install<BR>
--- END APACHE ---<BR>
<BR>
-- PHP --<BR>
cd ../php-4.1.1/<BR>
./configure&nbsp; --with-apxs=/usr/local/apache/bin/apxs --with-pgsql --with-mysql --with-ibm-db2=/usr/IBMdb2/V7.1<BR>
make<BR>
make install<BR>
-- END PHP ---<BR>
<BR>
-- LIB --<BR>
vim /etc/ld.so.conf<BR>
add line: /usr/IBMdb2/V7.1/lib<BR>
execute: ldconfig<BR>
-- END LIB --<BR>
<BR>
To Solve the error ODBC_CONNECT exec the db2profile at the apachectl!!! Like this!<BR>
<BR>
-- APACHE EDIT TO RUN DB2 --<BR>
vim /usr/local/apache/bin/apachectl<BR>
add line: . /usr/home/db2inst1/sqllib/db2profile<BR>
-- END APACHE EDIT TO RUN DB2 --<BR>
<BR>
NOW run /usr/local/apache/bin/apachectl startssl<BR>
<BR>
DONE !!!!!<BR>
<BR>
You have a DB2 + APACHE + SSL + PHP + MYSQL + POSTGRES .<BR>
<BR>
Enjoy <BR>
<BR>
[]�s<BR>
Helio Ferenhof</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="18343"></A>
 <DIV class="note">
  <STRONG>whuang at cadvision dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#18343">19-Jan-2002 02:32</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If you (still) get that annoying error like and you're using Access:<BR>
<BR>
MSaccess DSN(Microsoft Jet engine couldn't open the database 'Unknow'.<BR>
Another user is using it exclusively, or you dont have permission to use<BR>
it).<BR>
<BR>
Make sure your access *.mdb file is not on a network drive. Put it on C: or D: disable all security first so you can test the connection. Once you can verify that you can connect add appropriate passwords, group access, etc.<BR>
<BR>
-=WH=-</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="17570"></A>
 <DIV class="note">
  <STRONG>bill at ergoitsolutions dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#17570">14-Dec-2001 06:36</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
odbc connect to Oracle 8.0.xxx / NT4 / IIS4 / php.exe (4.1.0)
<BR>
had a lot of trouble connecting kept receiving the 12154 TNS error.&nbsp; 
<BR>
Found a really useful hint in a mail msg on phpbuilder.&nbsp; <A href="http://www.phpbuilder.com/mail/php-db/2001051/0192.php" rel="nofollow" target="_blank">http://www.phpbuilder.com/mail/php-db/2001051/0192.php</A>
<BR>
Had to strip the &lt;cr&gt;'s out of both sqlnet.ora and tnsnames.ora to get a connection established.&nbsp; Also had trouble in php.ini need to 
<BR>
fully qualify extension_dir on NT if you leave the last \ on the dir 
<BR>
name it is replaced with a /</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="17204"></A>
 <DIV class="note">
  <STRONG>Mahmoud at iastate dot edu</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#17204">29-Nov-2001 08:35</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
WINNT 4 Workstation, PHP4
<BR>

<BR>
odbc_connect() kept giving me weird errors when trying to connect to a MSaccess DSN(Microsoft Jet engine couldn't open the database 'Unknow'. Another user is using it exclusively, or you dont have permission to use it).
<BR>

<BR>
After going nuts for a while, I realized that my database name had a space in it (course surveys.mdb), I shortened the name to eliminate the space .. and everything worked fine.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="17056"></A>
 <DIV class="note">
  <STRONG>lomaky at yahoo dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#17056">23-Nov-2001 10:30</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
// simple conection
<BR>

<BR>

<BR>
$cnx = odbc_connect('cliente','Administrador','');&nbsp; 
<BR>
//query
<BR>
$SQL_Exec_String =&nbsp; "select * from Clientes";&nbsp; &nbsp; 
<BR>
//ejecucion query
<BR>
$cur= odbc_exec( $cnx, $SQL_Exec_String );&nbsp; 
<BR>
echo&nbsp; "&lt;table border=1&gt;&lt;tr&gt;&lt;th&gt;Dni&lt;/th&gt;&lt;th&gt;Nombre&lt;/th&gt;".&nbsp; 
<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; "&lt;th&gt;codigo&lt;/th&gt;&lt;th&gt;ciudad&lt;/th&gt;&lt;/tr&gt;\n";&nbsp; 
<BR>
&nbsp;&nbsp;&nbsp; while( odbc_fetch_row( $cur ) ) {&nbsp; 
<BR>
&nbsp;&nbsp; &nbsp; &nbsp; $Dni= odbc_result( $cur, 1 );&nbsp; 
<BR>
&nbsp;&nbsp; &nbsp; &nbsp; $Nombre= odbc_result( $cur, 2 );&nbsp; 
<BR>
&nbsp;&nbsp; &nbsp; &nbsp; $codigo= odbc_result( $cur, 3 ); 
<BR>
&nbsp;&nbsp; &nbsp; &nbsp; $ciudad= odbc_result( $cur, 4 ); 
<BR>
&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; echo&nbsp; "&lt;tr&gt;&lt;td&gt;$Dni&lt;/td&gt;&lt;td&gt;$Nombre&lt;/td&gt;".&nbsp; 
<BR>
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "&lt;td&gt;$codigo&lt;/td&gt;&lt;td&gt;$ciudad&lt;/td&gt;&lt;/tr&gt;\n";&nbsp; 
<BR>
&nbsp;&nbsp;&nbsp; }&nbsp; 
<BR>
&nbsp;&nbsp;&nbsp; echo&nbsp; "&lt;/table&gt;";</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="16919"></A>
 <DIV class="note">
  <STRONG>root at mediamonks dot net</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#16919">19-Nov-2001 12:03</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Due to multiple requests, more for DSN-less connections:
<BR>

<BR>
<SPAN class="default">&lt;?php
<BR>
$db_connection </SPAN><SPAN class="keyword">= new </SPAN><SPAN class="default">COM</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"ADODB.Connection"</SPAN><SPAN class="keyword">); 
<BR>

<BR>
</SPAN><SPAN class="default">$db_connstr </SPAN><SPAN class="keyword">= </SPAN><SPAN class="string">"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="</SPAN><SPAN class="keyword">. </SPAN><SPAN class="default">realpath</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"../databases/database.mdb"</SPAN><SPAN class="keyword">) .</SPAN><SPAN class="string">" ;DefaultDir="</SPAN><SPAN class="keyword">. </SPAN><SPAN class="default">realpath</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"../databases"</SPAN><SPAN class="keyword">); 
<BR>
</SPAN><SPAN class="default">$db_connection</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">open</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">$db_connstr</SPAN><SPAN class="keyword">); 
<BR>
</SPAN><SPAN class="default">$rs </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$db_connection</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">execute</SPAN><SPAN class="keyword">(</SPAN><SPAN class="string">"SELECT * FROM Table"</SPAN><SPAN class="keyword">);
<BR>
</SPAN><SPAN class="default">$rs_fld0 </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Fields</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">0</SPAN><SPAN class="keyword">);
<BR>
</SPAN><SPAN class="default">$rs_fld1 </SPAN><SPAN class="keyword">= </SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Fields</SPAN><SPAN class="keyword">(</SPAN><SPAN class="default">1</SPAN><SPAN class="keyword">);
<BR>
while (!</SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">EOF</SPAN><SPAN class="keyword">) {
<BR>
&nbsp; print </SPAN><SPAN class="string">"$rs_fld0-&gt;value $rs_fld1-&gt;value\n"</SPAN><SPAN class="keyword">;
<BR>
&nbsp; </SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">MoveNext</SPAN><SPAN class="keyword">(); </SPAN><SPAN class="comment">/* updates fields! */
<BR>
</SPAN><SPAN class="keyword">}
<BR>
</SPAN><SPAN class="default">$rs</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Close</SPAN><SPAN class="keyword">();
<BR>
</SPAN><SPAN class="default">$db_connection</SPAN><SPAN class="keyword">-&gt;</SPAN><SPAN class="default">Close</SPAN><SPAN class="keyword">();
<BR>
</SPAN><SPAN class="default">?&gt;
<BR>
</SPAN>
<BR>
(Prints first 2 columns for each row.)</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="13928"></A>
 <DIV class="note">
  <STRONG>cs at coolspot dot de</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#13928">10-Jul-2001 08:01</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
We've tried hard to connect from php to our IBM DB2 RS/6000 Server. It worked after we compiled with --ibm-db2= option, but it was unbelievable
<BR>
slow.
<BR>

<BR>
No, just testing some options, we found out that it went from very slow (getting 100 records lasts 1 till 10 seconds) to fast access (almost same speed as with using JDBC from Servlets) to 0.2 till 0.3 seconds.
<BR>

<BR>
We simply added the optional parameter Cursortype to odbc_connect, and with the cursortype SQL_CUR_USE_ODBC it changed in that way!
<BR>

<BR>
Hope this helps anybody who must connect to db2 ;)</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="13353"></A>
 <DIV class="note">
  <STRONG>ckelly at powerup dot com dot au</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#13353">13-Jun-2001 04:42</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
To connect to a PROGRESS database using ODBC you must have SQL_CUR_USE_ODBC&nbsp; as the 4th parameter eg odbc_connect(DSN,uname,password,SQL_CUR_USE_ODBC ) otherwise you can pass queries but no results are ever returned .</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="11851"></A>
 <DIV class="note">
  <STRONG>cpoirier at shelluser dot net</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#11851">09-Mar-2001 09:26</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
After much testing, and I think supported by a comment I found in the code, I have come to a disturbing conclusion: odbc_connect() in PHP4.04pl1 is really an odbc_pconnect(), with all the implications for transaction scoping.&nbsp; Specifically, each time you call odbc_connect( "X", "" "" ), you will get the same physical ODBC Connection, and odbc_commit() and odbc_rollback() will affect all copies.&nbsp; The only solution I could find was to use several different DSNs to access the database.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="10934"></A>
 <DIV class="note">
  <STRONG>fc99 at smm dot de</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#10934">27-Jan-2001 02:23</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If you don't want to specify your login credentials on your web server, you can leave the login fields blank to use the integrated windows security like here:
<BR>

<BR>
odbc_connect("DSN=DataSource","",""); 
<BR>

<BR>
Make sure you have switched your system dsn to integrated security, too !
<BR>

<BR>
(works on windows machines only, of course)
<BR>

<BR>
flo.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="10930"></A>
 <DIV class="note">
  <STRONG>SilencerX at optidynamic dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#10930">26-Jan-2001 11:31</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If like me you are using openlink from unix to access an MS Access database on an NT/Win2k machine and find out that your INSERT queries don't do anything and don't report any errors, use odbc_pconnect().
<BR>

<BR>
I couldn't understand what was going on and after a bit of research I found out that with MySQL they recommended using mysql_pconnect() for INSERT queries. I tried the same thing with odbc and it worked.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="10416"></A>
 <DIV class="note">
  <STRONG>garretg at otable dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#10416">02-Jan-2001 10:03</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If you're connecting to a SQL server database through ODBC, you must set the default database of the ODBC DSN to the database you want to use.
<BR>

<BR>
There is no way to specify the database name in odbc_connect or odbc_pconnect, just the DSN name, username, and password.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="9415"></A>
 <DIV class="note">
  <STRONG>phobo_AT_paradise.net.nz</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#9415">02-Nov-2000 02:01</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
If using Openlink to connect to a Microsoft Access database, you will most likely fine tha odbd_connect() works fine, but discover that ANY query will produce odd results; with SELECT queries failing with "[OpenLink][ODBC][Driver]Driver not capable, SQL state
<BR>
S1C00 in SQLExecDirect in xxxx.php on line xx" and INSERT / DELETE queries warning "No tuples available at this result index".
<BR>

<BR>
In this case, use the SQL_CUR_USE_ODBC cursor!
<BR>

<BR>
This had me stumped for quite some time; because it was the odbc_exec() which was seemingly at fault... :)
<BR>

<BR>
Siggy</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="5900"></A>
 <DIV class="note">
  <STRONG>cnewbill at onewest dot net</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#5900">18-May-2000 12:55</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
Alot of people share the same kind of problems getting this setup on linux.&nbsp; I was assigned this problem 2 days ago and I was successful.&nbsp; My combination was PHP4 RC2, Easysoft OOB, and unixODBC.&nbsp; These three products work very well together and are real easy to install.&nbsp; More info <A href="http://www.easysoft.com/products/oob/main.phtml." rel="nofollow" target="_blank">http://www.easysoft.com/products/oob/main.phtml.</A> ps also works good with Perl's DBI.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV>
 <A name="4279"></A>
 <DIV class="note">
  <STRONG>dipakp at atinet dot com</STRONG><BR>
  <A href="http://us2.php.net/manual/en/function.odbc-connect.php#4279">09-Mar-2000 04:43</A>
  <DIV class="text">
<DIV class="phpcode"><CODE><SPAN class="html">
OpenRDA ODBC from <A href="http://www.odbcsdk.com/" rel="nofollow" target="_blank">http://www.odbcsdk.com</A> allows you to access MS Access, SQL Server and other PC databases from LINUX and many other UNIX platforms.</SPAN>
</CODE></DIV>
  </DIV>
 </DIV></DIV>

 <DIV class="foot"><A href="http://us2.php.net/manual/add-note.php?sect=function.odbc-connect&redirect=http://us2.php.net/manual/en/function.odbc-connect.php"><IMG src="./PHP_odbc_connect - Manual_files/notes-add.gif" alt="add a note" width="13" height="13" class="middle"></A> <SMALL><A href="http://us2.php.net/manual/add-note.php?sect=function.odbc-connect&redirect=http://us2.php.net/manual/en/function.odbc-connect.php">add a note</A></SMALL></DIV>
</DIV><BR><!--UdmComment-->
<DIV class="manualnavbar manualnavbar_bottom">
 <SPAN class="next">
  <A href="http://us2.php.net/manual/en/function.odbc-cursor.php">odbc_cursor<IMG src="./PHP_odbc_connect - Manual_files/caret-r.gif" alt="&gt;" width="11" height="7"></A>
 </SPAN>
 <SPAN class="prev">
  <A href="http://us2.php.net/manual/en/function.odbc-commit.php"><IMG src="./PHP_odbc_connect - Manual_files/caret-l.gif" alt="&lt;" width="11" height="7">odbc_commit</A>
 </SPAN>
 <HR>
 <SPAN class="lastupdated">Last updated: Fri, 05 Mar 2010</SPAN>
 <DIV class="langchooser">
  &nbsp;
 </DIV>
</DIV>
<!--/UdmComment-->


 </DIV>
 <DIV class="cleaner">&nbsp;</DIV>
</DIV>

<DIV id="footnav">
   <A href="http://us2.php.net/source.php?url=/manual/en/function.odbc-connect.php">show source</A> |
 <A href="http://us2.php.net/credits.php">credits</A> |
 <A href="http://us2.php.net/sitemap.php">sitemap</A> |
 <A href="http://us2.php.net/contact.php">contact</A> |
 <A href="http://us2.php.net/contact.php#ads">advertising</A> |
 <A href="http://us2.php.net/mirrors.php">mirror sites</A>
</DIV>

<DIV id="pagefooter">
 <DIV id="copyright">
  <A href="http://us2.php.net/copyright.php">Copyright © 2001-2009 The PHP Group</A><BR>
  All rights reserved.
 </DIV>

 <DIV id="thismirror">
  <A href="http://us2.php.net/mirror.php">This mirror</A> generously provided by:
  <A href="http://he.net/">Hurricane Electric</A><BR>
  Last updated: Wed Mar 10 09:01:40 2010 UTC
 </DIV>
</DIV>
<!--[if IE 6]>
<script type="text/javascript"> 
    /*Load jQuery if not already loaded*/ if(typeof jQuery == 'undefined'){ document.write("<script type=\"text/javascript\"   src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js\"></"+"script>"); var __noconflict = true; } 
    var IE6UPDATE_OPTIONS = {
        icons_path: "/ie6update/images/"
    }
</script>
<script type="text/javascript" src="/ie6update/ie6update.js"></script>
<![endif]-->

<UL id="gview-cmenu" class="gview-hidden" tabindex="9999"><LI class="gview-cmenu-item">Open Link in New Tab</LI><LI class="gview-cmenu-item">Download</LI></UL></BODY></HTML>